<template>
	<view>
		<u-sticky bgColor="#6492FF" offsetTop=0 customNavHeight=0>
			<navbox title="通知"></navbox>
		</u-sticky>
		<u-sticky bgColor="#f6f6f6" customNavHeight='110rpx'>
			<view class="tab">
				<view class="tab__item" v-for="(item,index) in tablist" :key="index"
					@click="clicktab(item,index)">
					<view class="tab__item__text">
						{{item.name}}
					</view>
					<view class="tab__item__line" v-if="curi==index">

					</view>
				</view>
			</view>
		</u-sticky>
		<view class="list" v-if="list.length>0">
			<view class="list__item" v-for="(item,index) in list" @click="navto('/pages/home/noticeinfo?id='+item.noticeId)" :key="index">
				<view class="list__item__title">
					{{item.noticeTitle}}
				</view>
				<view class="u-flex u-flex-y-center u-flex-between">
					<view class="list__item__content">
						{{item.descInfo}}
					</view>

					<view class="u-flex u-flex-y-center">
						<view class="list__item__wd">

						</view>
						<image src="/static/img/home/more.png" class="list__item__more" mode=""></image>
					</view>
				</view>
				<view class="list__item__time">
					{{item.createTime}}
				</view>
			</view>
			<u-loadmore @loadmore="loadmore" :status="morestatus" />
		</view>
		<view class="" v-else style="margin-top: 200rpx;">
			<u-empty mode="data" icon="/static/img/index/empty.png">
			</u-empty>
		</view>
	</view>
</template>

<script>
	import {
		noticelist
	} from '@/api/home.js'
	export default {
		data() {
			return {
				tablist: [{
						name: '公告',
						type: 2
					},
					{
						name: '站内信',
						type: 1
					}
				],
				curi: 0,
				pageSize: 10,
				pageNum: 1,
				list: [],
				noticeType:2,
				morestatus: 'loadmore',
			};
		},
		methods: {
			clicktab(item,index){
				this.curi=index
				this.noticeType=item.type
				this.pageNum=1
				this.list=[]
				this.getlist()
			},
			getlist() {
				
				noticelist({
					noticeType:this.noticeType,
					pageSize: this.pageSize,
					pageNum: this.pageNum
				}).then(res => {
					uni.stopPullDownRefresh()
					if (res.data.code == 200) {
						if (res.data.data.length == 0) {
							this.morestatus = 'nomore';
							return
						}else{
							this.morestatus = 'loadmore';
						}
						this.list = [...this.list, ...res.data.data]
					}
				})
			},
			loadmore(){
				if(this.morestatus=='nomore')return
				this.morestatus = 'loading';
				this.pageNum = ++this.pageNum;
				this.getlist()
			}
		},
		onLoad() {
			this.getlist()
		},
		onReachBottom() {
			this.loadmore()
		},
		onPullDownRefresh() {
			this.morestatus='loadmore'
			this.pageNum=1
			this.list=[]
			this.getlist()
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f6f6f6;
	}

	.tab {
		display: flex;
		// align-items: center;
		justify-content: space-between;
		padding: 26rpx 194rpx 25rpx;

		&__item {
			display: flex;
			flex-direction: column;
			align-items: center;
			min-width: 78rpx;

			&__text {
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 34rpx;
				color: #3E3D3D;
				line-height: 32rpx;
			}

			&__line {
				width: 78rpx;
				height: 10rpx;
				background: linear-gradient(235deg, #0059C9 0%, #4497FF 100%);
				border-radius: 5rpx;
				margin-top: 16rpx;
			}
		}
	}

	.list {
		padding: 0 16rpx 20rpx;

		&__item {
			margin-bottom: 25rpx;
			background: #FFFFFF;
			border-radius: 14rpx;
			padding: 34rpx 32rpx 36rpx 35rpx;

			&__title {
				font-family: Source Han Sans SC;
				font-weight: bold;
				font-size: 26rpx;
				color: #3E3D3D;
				line-height: 26rpx;
			}

			&__content {
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #707070;
				margin: 22rpx 0;
			}

			&__more {
				width: 13.19rpx;
				height: 26.39rpx;
				margin-left: 10rpx;
			}

			&__wd {
				width: 10rpx;
				height: 10rpx;
				background: #FF0000;
				border-radius: 50%;
			}

			&__time {
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #707070;
				line-height: 26rpx;
			}
		}
	}
</style>